<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="path" value="${pageContext.request.contextPath}" />
<html>
<head>
	<title>新增</title>
	<%@ include file="/WEB-INF/views/mis/common_inc.jsp"%>
</head>
<style>
</style>
<body style="width:100%;height:100%;overflow-x:hidden;overflow-y:auto">
	<form id="addForm" class="my-form"  method="post" > 
		<table class="form-table">
			#foreach( $field in $fieldList )
#if( $field.isPk != "Y"&&(${field.field}=="code"||${field.inputType}=="hidden"))
            <input type="hidden"  name="${field.field}"   value="${${model.modelL}.${field.field}}"/>
#end
#if( $field.isPk != "Y"&&${field.inputType}!="hidden"&&${field.field}!="code"&&${field.field}!="createCode"&&${field.field}!="updateCode"&&${field.field}!="updateTime"&&${field.field}!="createTime"&&${field.field}!="delFlag")
                    <tr>
#if( $field.type == "Date")
                        <td width="70px">#if(!$field.nullable)#end<label>${field.comment}：</label></td>
                        <td><input id="" name="${field.field}" type="text" class="lay-date"  autocomplete="off"  data-rule="${field.comment}:required;" placeholder="请选择时间" onclick="layui.laydate({elem: this})" value="${${model.modelL}.${field.field}}"/></td>
#else
                        <td width="70px">#if(!$field.nullable)#end<label>${field.comment}：</label></td>
                        <td>
#if(${field.inputType}=="input")
                        <input type="text"  name="${field.field}" placeholder="请输入${field.comment}" autocomplete="off"  data-rule="${field.comment}:required;#if(${field.validate})${field.validate};" data-msg="${field.comment}不符合规则" #else " #end value="${${model.modelL}.${field.field}}"/>
#elseif(${field.inputType}=="textarea")
                        <textarea style="height:100px;width:80%;border: 1px solid #c5c5c5;margin:5px;padding:5px;overflow:auto" name="${field.field}"  placeholder="请输入${field.comment}" autocomplete="off"  data-rule="${field.comment}:required;#if(${field.validate})${field.validate};" data-msg="${field.comment}不符合规则" #else " #end>${${model.modelL}.${field.field}}</textarea>
#elseif(${field.inputType}=="checkbox")
                        <input type="checkbox"  name="${field.field}" placeholder="请输入${field.comment}" autocomplete="off"  data-rule="${field.comment}:required;#if(${field.validate})${field.validate};" data-msg="${field.comment}不符合规则" #else " #end   value="${${model.modelL}.${field.field}}"/>
#elseif(${field.inputType}=="radio")
                        <input type="radio"  name="${field.field}" placeholder="请输入${field.comment}" autocomplete="off"  data-rule="${field.comment}:required;#if(${field.validate})${field.validate};" data-msg="${field.comment}不符合规则" #else " #end   value="${${model.modelL}.${field.field}}"/>
#elseif(${field.inputType}=="date")
                        <input id="" name="${field.field}" class="lay-date" placeholder="请选择时间"  autocomplete="off"  data-rule="${field.comment}:required;#if(${field.validate})${field.validate};" data-msg="${field.comment}不符合规则" #else " #end  onclick="layui.laydate({elem: this})"  value="${${model.modelL}.${field.field}}"/>
#elseif(${field.inputType}=="file")
                        <input type="file"  name="${field.field}" placeholder="请上传文件" autocomplete="off"  data-rule="${field.comment}:required;"  value="${${model.modelL}.${field.field}}"/>
#end
                        </td>
#end
                    </tr>
#end
#end
		</table>
		<div class="btn-div" style="text-align: center;margin-top: 20px;">
			<input onClick="saveAdd()" type="button" class="layui-btn layui-btn-small submit-btn" value="立即提交" />
			<span class="msg-box" id="holdMsg"></span>
		</div>
	</form>
	
</body>
<script type="text/javascript">
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引，用于关闭当前弹窗
 
var url= "${path}/${model.modelL}/saveAdd"; 	
$(function(){
	//表单提交方式一：nice-validator验证+提交
	$('#addForm').validator({
	    timely:0,//提交时触发[0-提交，1-blur,2-input,3-input and blur]
// 	    theme://设置错误提示的样式
	    stopOnError: true,
	    target: function(input) {
	        return $("#holdMsg");
	    },
	    valid:function(form){
	    	var me = this;
	        me.holdSubmit();// 提交表单之前，hold住表单，防止重复提交
	        //提交表单
	    	$.post(url,$(form).serialize(),function(d){
                me.holdSubmit(false);// 提交表单成功后，释放hold
	    		d=$.parseJSON(d);
                if(d.returnCode=="SUCCESS"){
                	//如果成功关闭弹窗并刷新父页面列表
                	parent.layer.close(index);//关闭弹窗
				    parent.doSearch_dg();//刷新父页面
                }else{
                	//如果失败弹出提示
				    layer.msg(d.message);
                }
	    	});
	    }
	});
 	//表单提交方式二：easyui表单提交+onSubmit中自定义校验
// 	$("#addForm").form({
// 		   onSubmit: function(){
			   //校验表单 
// 			   return false;//不通过
// 			   return true;//通过
// 			   //禁止重复提交
// 			   $(".submit-btn").attr("disabled",true);
// 		   },    
// 		   success:function(data){  
// 			   data=$.parseJSON(data);
// 			   alert(data.message);
// 		   }
// 	   });
});
//保存新增
function saveAdd(){
	$("#addForm").submit();
}
</script>
</html>